/*
 * @Description: 积分科目数据Hook
 * @Date: 2022-12-16 13:30:40
 * @Author: lizhiqiang
 */
import { GO } from "@/request/integralaccounttitle"
import { useEffect, useState } from "react"

export default function useAccountTitle () {
    const [ accountTitleOptions, setAccountTitleOptions ] = useState<Array<Record<string,unknown>>>([])
    const getData = async () => {
        const { code, data } = await GO({page: 1, limit: 1000} as any)
        if ( code === 200 ) {
            setAccountTitleOptions( data?.list?.map((item: { accountTitleName: any; accountTitleCode: any })=>{
                return {
                    ...item,
                    label:item.accountTitleName,
                    value:item.accountTitleCode
                }
            }) )
        } else {
            setAccountTitleOptions( [] )
        }
    }
    useEffect( () => {
        getData()
    }, [] )
    return accountTitleOptions
}